#include<iostream>
#include<unistd.h>
#include<vector>
#include "blockqueue.hpp"
#include"task.hpp"
using namespace std;




void * producter(void* args)
{
    blockqueue<task>* bt = static_cast<blockqueue<task>*>(args);

    while(true)
    {
        int x = rand() % 10;
        int y = rand() % 10;
        task t(x,y,opers[rand()%opers.size()]);
        t.run();
        bt->push(t);
        cout << "生产一个数据： " << t.Gettask() << endl;
        sleep(1);
    }
    

    return nullptr;
}

void* consumer(void* args)
{
    
    blockqueue<task>* bt = static_cast<blockqueue<task>*>(args);
    while(true)
    {
        task data = bt->pop();
        cout << "消费一个数据： " << data.Getresult() << endl; 
    }
}

int main()
{
    blockqueue<task>* bq = new blockqueue<task>();
    srand(time(nullptr));
    pthread_t ctid,ptid;
    pthread_create(&ptid,nullptr,producter,bq);
    pthread_create(&ctid,nullptr,consumer,bq);

    pthread_join(ctid,nullptr);
    pthread_join(ptid,nullptr);

    return 0;
}